package liurong.driver.compareprofile;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.List;

import org.junit.Test;

public class CompareMessage {

	@Test
	public void compare() throws Exception {
		OutputStream out = new FileOutputStream(new File("D:/laugage/differenet.properties"));
		BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(out, "gbk"));

		// File chinaFile = new File("D:/laugage/message_zh_CN.properties");
		File chinaFile = new File("D:/laugage/message_en_US.properties");
		InputStream chinaInputStream = new FileInputStream(chinaFile);
		BufferedReader chinaBufferedReader = new BufferedReader(new InputStreamReader(chinaInputStream, "gbk"));

		// File enFile = new File("D:/laugage/message_en_US.properties");
		File enFile = new File("D:/laugage/message_zh_CN.properties");
		InputStream enInputStream = null;
		InputStreamReader enInputStreamReader = null;

		BufferedReader enBufferedReader = null;
		String chinaStartString = null;
		String chinaReadLine = null;
		String enReadLine = null;
		String enStartString = null;

		boolean flag = false;
		// 循环中文的
		while (chinaBufferedReader.ready()) {
			flag = false;
			chinaReadLine = chinaBufferedReader.readLine();
			if (chinaReadLine.startsWith("#")) {
				continue;
			}
			chinaStartString = chinaReadLine.split("=")[0].trim();

			enInputStream = new FileInputStream(enFile);
			enInputStreamReader = new InputStreamReader(enInputStream, "gbk");
			enBufferedReader = new BufferedReader(enInputStreamReader);

			// 判断在中文文档中不在引文文档中
			while (enBufferedReader.ready()) {
				enReadLine = enBufferedReader.readLine();
				if (enReadLine.startsWith("#")) {
					continue;
				}
				enStartString = enReadLine.split("=")[0].trim();
				if (chinaStartString.equals(enStartString)) {
					flag = true;
					break;
				}
			}
			enBufferedReader.close();
			enInputStreamReader.close();
			enInputStream.close();

			if (!flag) {
				bufferedWriter.write(chinaReadLine);
				bufferedWriter.write("\r\n");
			}
		}

		bufferedWriter.flush();

		bufferedWriter.close();
		out.close();
		chinaBufferedReader.close();
		chinaInputStream.close();
	}
	
	@Test
	public void fun1() {
		List<String> aList = new ArrayList<String>();
		aList.add("liu");
		
		System.out.println(aList);
		
		aList.remove(null);
		
		System.out.println(aList);
	}
}
